package com.jerry.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GatewayConfig {

    /**
     * 配置了id为payment_getList的路由规则
     * 当访问 http://localhost:9527/payment/get 时，会自动转发到地址 http://provider-payment/payment/get
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        routes.route("payment_getList",
                  r -> r.path("/payment/get")
                        .uri("lb://provider-payment/payment/get")).build();
        return routes.build();
    }
}
